package newx.com.control
{
	import flash.display.Bitmap;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	import newx.utils.BitmapAPI;
	
	/** 动态提示框				version 1.0
	 * 	（属于NxToolTips子框体，一般不独立使用）
	 * @author wangpg	2011.03.24
	 * 
	 */	
	public class NxToolTipsNotePanel extends Sprite
	{
		private var bg			:Sprite		=	new Sprite;
		private var txt		:TextField	=	new TextField();
		
		/**
		 * 
		 * @param textColor 初始化背景颜色为NxTooltips默认背景颜色
		 * @param pos 初始化显示框纵坐标
		 * 
		 */		
		public function NxToolTipsNotePanel(textColor:uint, pos:int)
		{
			this.x = pos;
			
			this.addChild(this.bg);
			
			var format	:TextFormat	=	new TextFormat();
//			format.leftMargin		=	0;
//			format.rightMargin		=	0;
			format.color			=	textColor;
			format.size				=	12;
//			format.font				=	"Arial";
//			format.leading			=	1;
			
			this.txt.width			=	0;
			this.txt.height			=	0;
			this.txt.multiline		=	true;
			this.txt.wordWrap		=	true;
			this.txt.selectable		=	false;
			this.txt.defaultTextFormat	=	format;
//			this.txt.filters		=	[new ColorMatrixFilter()];
			this.addChild(this.txt);
		}
		
		public function printText(str:String,maxW:uint=240,maxH:uint=200):void
		{
			this.txt.width			=	maxW;
			this.txt.height			=	maxH;
			this.txt.htmlText		=	str;
			this.txt.width			=	this.txt.textWidth + 6;
			if(this.txt.bottomScrollV > 1)
			{
				this.txt.height		=	this.txt.textHeight + 6;
			}
			else
			{
				this.txt.height		=	this.txt.textHeight + 4;
			}
			this.txt.x				=	5;
			this.txt.y				=	2;
		}
		
		public function drawBg(borderColor:uint, bgColor:uint, rate:int):void
		{
			this.bg.graphics.clear();
			this.bg.graphics.lineStyle(1.1,borderColor,0.6);
			this.bg.graphics.beginFill(bgColor);
			this.bg.graphics.drawRoundRect(0,0,this.txt.width + 11,this.txt.height + 6,
				rate,rate);
			this.bg.graphics.endFill();
		}
		
		/** 如果是背景是位图，则调用此方法设置
		 * 
		 */		
		public function constructBitmapBg(bgImageData:DisplayObject,bgScale9Grid:Rectangle):void
		{
			if(bgImageData)
			{
				this.bg.graphics.clear();
				while(this.bg.numChildren)			this.bg.removeChildAt(0);
				
				if(bgImageData is Bitmap)
				{
					var w		:Number				=	this.txt.width + 8;
					if(w < bgScale9Grid.x * 2)
					{
						w							=	bgScale9Grid.x * 2;
					}
					this.bg.addChild(BitmapAPI.scaleBitmap(	bgImageData as Bitmap,
						w,this.txt.height + 3,
						bgScale9Grid));
				}
				else
				{
					//					IO.traceLog('   ',this,'当前使用的是 swf 背景');
					bgImageData.width			=	this.txt.width + 8;
					bgImageData.height			=	this.txt.height + 3;
					this.bg.addChild(bgImageData);
				}
			}
		}
		
		/**	设置Aphla值
		 * 
		 */		
		public function setAphla(bgAlpha:Number):void
		{
			this.bg.alpha = bgAlpha;
		}
	}
}